import GameItemModel from "../../base/GameItemModel";
import BaseItemView from "../../../cfw/mvc/BaseItemView";
import BigExportC from "../BigExportC";
import ModuleManager from "../../../cfw/module/ModuleManager";
import { ResType } from "../../../cfw/res/ResInterface";
import ResItem from "../../../cfw/res/ResItem";


const { ccclass, property } = cc._decorator;

@ccclass
export default class BigExportPage1Item extends BaseItemView {

	@property({ type: cc.Label, displayName: "gameName$VLabel" })
	gameName$VLabel: cc.Label = null;

	@property({ type: cc.Sprite, displayName: "gameIcon$VSprite" })
	gameIcon$VSprite: cc.Sprite = null;


	@property([cc.Node])
	bgList: cc.Node[] = []

	protected model: GameItemModel;
	protected controller: BigExportC;

	protected isBig: boolean = false;
	onLoad() {

	}

	refresh() {
		for (let index = 0; index < this.bgList.length; index++) {
			const element = this.bgList[index];
			if (this.getIndex() % 3 == index) {
				element.active = true;
			} else {
				element.active = false;
			}
		}
		if (this.model) {
			this.gameName$VLabel.string = this.model.getGameName()
			ModuleManager.publicLoader().loadRes(this.model.getGameIcon(), ResType.Remote, (err, tex: ResItem) => {
				if (err || !cc.isValid(this.node)) {
					return;
				}
				this.gameIcon$VSprite.spriteFrame = new cc.SpriteFrame(tex.getRes())
			})
		}

	}


	update() {
		if (!this.isBig) {
			let pos = this.node.parent.convertToWorldSpaceAR(this.node.getPosition())
			let vs = cc.view.getVisibleSize()
			if (pos.x < vs.width - this.node.width / 2) {
				this.isBig = true;
				// this.node.scale = this.node.scale + 0.2
				cc.tween(this.node).by(0.2, { scale: 0.2 }).by(0.2, { scale: -0.2 }).start()
			}
		}
	}



	onButtonClick() {
		this.controller.clickPage1Game(this.model)
	}



}